@extends('admin.public.master')
@section('content')
    <div class="content-wrapper">
        <div class="content-wrapper-before"></div>
        <div class="content-header row">
            <div class="content-header-left col-md-1 col-4 mb-2">
                <a href=""><h5 class="content-header-title">货品列表</h5></a>
            </div>
            <div class="content-header-left col-md-1 col-4 mb-2">
                <a href="{{route('goods.product.create',['goods'=>$goods->id])}}"><h5 class="content-header-title">添加货品</h5></a>
            </div>
        </div>
    </div>
    <div class="content-body">
        <div class="card">
            <div class="card-body table-responsive">
                <table class="table table-bordered table-striped">
                    <thead>
                    <tr>
                        <th>货品编号</th>
                        <th>货品属性</th>
                        <th>附加价格</th>
                        <th>货品库存</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                @foreach($products as $product)
                        <tr>
                            <td class="mr-auto mt-auto" scope="row">{{$product->id}}</td>
                            <td class="mr-auto mt-auto" scope="row">
                            {{$product->getAttrName($product->attributeArr)}}
                            </td>
                            <td class="mr-auto mt-auto">{{$product->extraPrice}}</td>
                            <td class="mr-auto mt-auto">{{$product->inventory}}</td>
                            <td class="mr-auto mt-auto">
                                <a href="{{route('goods.product.edit',['product'=>$product,'goods'=>$goods])}}"><button type="button" class="btn btn-info ">编辑</button></a>
                                <button onclick="del(this)" type="button" class="btn btn-danger">删除</button>
                                <form action="{{route('goods.product.destroy',['product'=>$product,'goods'=>$goods])}}" method="post">
                                    @csrf @method('DELETE')
                                </form>
                            </td>
                        </tr>
                    @endforeach

                    </tbody>
                </table>
            </div>
        </div>
    </div>
    @endsection
@push('js')
    <script>
        function del(obj) {
            swal({
                title: '确定删除吗？',
                text: '你将无法恢复它！',
                type: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: '确定删除！',
                cancelButtonText: '取消删除！',
                confirmButtonClass: 'btn btn-success',
                cancelButtonClass: 'btn btn-danger',
                buttonsStyling: false
            }).then(function(value) {
                if(value.value){
                    $(obj).next('form').submit();
                }
            })

        }
    </script>
@endpush
